<?php
class SendMailAction extends Action
{
	/**
	 * 邮件发送
	 * @access protected
	 * @param string $message 错误信息
	 * @return void
	 */
	protected function sendMail($users, $title, $body, $dir) {
		Vendor('PHPMailer.SendMail');
		$mail = new SendMail();
		$mailDir = APP_PATH . '/Mail/' . $dir;
		$ViewTitle = Think::instance('View');
		$ViewBody = Think::instance('View');
		$ViewTitle->assign($title);
		$ViewBody->assign($body);
		$title = $ViewTitle->fetch($mailDir . '/title.html');
		$body = $ViewTitle->fetch($mailDir . '/body.html');
		return $mail->setParameAndSend($title, $body, $users);
	}

	public function index(){

	}

	public function sendM1(){
		$map = array();
		$u = array();
		//获取美工数量
		$map['role_id'] = 3;
		$users = M('RoleUser')->field('user_id as uid')->where($map)->select();
		if(count($users) > 0){
			$UserModel = M('User');
			$TaskAllotModel = D('TaskAllot');
			//获取美工 一次获取一个美工
			foreach($users as $user){
				$uid = $user['uid'];
				$userInfo = $UserModel->field('num,email')->find($uid);
				//获取单个人今天分配的任务详细
				$tasks = $TaskAllotModel->getUserDayAllot($uid);
				if($tasks){
					$time = time();
					$title['num'] = $userInfo['num'];
					$title['date'] = date('Y-m-d', $time);
					$body['date'] = date('Y-m-d G:i:s', $time);
					$body['tasks'] = $tasks;
					unset($u);
					$u[$userInfo['num']] = $userInfo['email'];
					$rs = $this->sendMail($u, $title, $body, 'dayTask');
					if($rs){
						SD($users);
					}else{
						Log::write($title['num'].'工作邮件发送失败');
					}
				}
			}
		}
		//获取审核数量

	}
}
?>
